home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
vi.arc
/
VI.DOC
< prev
Wrap
Text File
|
1987-05-28
|
17KB
|
849 lines
------------------------------------------------------------
===== VI =====
------------------------------------------------------------
VI is a screen text editor written for the IBM PC. It
has been given the same name as the screen editor for the
Berkeley Unix operating system. This is no coincidence:
with a few exceptions, this editor is a subset of the lat-
ter. Users familiar with Unix can skip to the command
summary at the end of this file.
This editor requires an 80-column display, MS-DOS 1.1
or better, and 128K of memory.
Getting started
------- -------
To edit an existing file, type
vi name
as a DOS command. The first few lines of the file will then
appear on the screen, and you may use any of the editing
commands to modify it. For example:
dw delete a word
de delete a word, leaving punctuation
dd delete a line
3dd delete three lines
itextEND insert text
/string search for string
xp transpose characters (actually two commands)
In addition, all of the keys on the numeric keypad perform
as labeled. When you are finished editing, type :w<cr> to
update the copy of the file residing on disk, and then type
:q<cr> to quit VI. The command :wq<cr> combines the above
two "colon" commands into a single command.
If you had not modified the file in the above editing
session, the ":w" would have been superfluous and you could
quit with just ":q". If you had made changes, but did not
want to save them, you should also omit the ":w", but use
":q!" to quit so as to avoid an error message.
If the file named in the DOS command "vi name" does not
exist, VI starts with an empty file, into which text can be
inserted. This is how VI can be used to create a file.
VI States
-- ------
VI has three states, all of which occur in at least one
of the above commands. They are,
o Command mode. This is the normal and initial
state. All commands return here after completion.
o Insert mode. Characters typed in insert mode are,
as the name implies, copied into the file instead
of interpreted as commands. The "End" and "In-
sert" keys return VI to command mode (and vice
versa for "Insert"). The "Escape" key works as in
DOS (as opposed to Unix): it deletes characters
typed so far in the current line. In this mode
the cursor is larger than in command mode.
o Last line mode. In this mode the editor is read-
ing text for a ":" command or a "/" or "?" search.
The text ends with <cr>; "Escape" deletes the text
but not the ":", "/", or "?" (unless there is no
text).
Counts Before VI Commands
------ ------ -- --------
Many VI commands can be preceded by a number. The
effect of this number is usually to repeat the effect of the
command. Sometimes, however, it has other meanings. In
many cases it is ignored.
The Screen
--- ------
The first 24 lines of the screen are used to display
the file; the last line is used for last line mode and for
messages. Lines past the end of the file appear as lines
consisting of a single tilde ("~"). Tabs are expanded to
columns 9, 17, 25, ..., 73, 1, .... Long lines are wrapped
around, so that they may take up several lines of the
screen. "@" lines indicate that the next line is too long
to fit on the remainder of the screen. The user should not
create lines too long to fit on a screen, although VI will
not stop him from trying.
In case DOS (or a program bug) scrambles the screen, ^L
will restore it to what it should be.
If a command causes the cursor to move to a part of the
file which is not currently displayed on the screen, VI will
automatically scroll as necessary. VI also has commands to
explicitly request scrolling:
^F or PgDn Move the screen Forward one screenful,
keeping the last two lines of the old
screen as the first two lines of the
new.
^B or PgUp Move Backwards one screenful.
^D Move Down 1/2 screen.
^U Move Up 1/2 screen.
Motion Commands
------ --------
The arrows on the numeric keypad perform as labeled.
Also, VI has a rich assortment of other commands to move the
cursor. These are:
+ or <cr> Move the cursor to the first nonblank
character of the next line in the
file. (All motions referring to lines
put the cursor on the first nonblank
character of that line.)
- Move to the previous line.
$ Move to the end of the current line.
0 Move to the beginning of the line.
fx Find the next occurrence of the given
character. The search is limited to
the current line.
Fx Same as fx, backwards.
; Repeat the previous f or F.
/string<cr> Search for the next occurrence of the
given string. This search starts at
the current position, but may wrap
around the beginning of the file.
?string<cr> Same as "/", searching backwards.
n Repeat last "/" or "?" search.
N Same as "n", in the opposite direc-
tion.
H or Home Move the cursor to the first line of
the screen.
M The middle line of the screen.
L or End Move to the last line of the screen.
nG Move to the nth line of the file.
G Move to the last line.
% Move to the matching parenthesis,
bracket, or brace.
The Delete Operator
--- ------ --------
If one of the above motions is preceded by the letter
"d", then VI will delete the text, from the old position to
the new position. This called an operator because it chan-
ges the effect of the ensuing motion command. The repeti-
tion count for the motion command may either precede or
follow the "d"; the effect is the same.
Also, "d" may be doubled (i.e. dd or 7dd) to delete one
or several lines. If D is capitalized, it deletes through
the end of the line.
Other operators are "c" (change) and "y" (yank), de-
scribed later.
Other Deletion Commands
----- -------- --------
x or Delete Functions the same as dSpace; deletes
one character.
X Deletes backwards one character; same
as dh.
Insert Mode
------ ----
A number of commands place the user in insert mode.
They are:
i Enter insert mode, inserting text before the
current character.
a Insert after the current character.
A Insert after end of line.
o Open a new line after the current line and
enter insert mode.
O Open before current line.
c<motion>, cc, C "c" is an operator, similar to
"d". It deletes text and leaves the editor
in insert mode. For example, "cw" changes
the current word; "cc", the current line.
Other Modification Commands
----- ------------ --------
rx Replaces the current character with the char-
acter x.
J Joins two lines; i.e. concatenates them,
adding a space between them.
Undo and Repeat
---- --- ------
In case of a mistake, the "u" command will undo the
effect of the last command which modified the file. Only
the most recent change can be undone in this way.
The dot command (".") will repeat the last command
which changed the file.
Moving Text
------ ----
To move part of a file, one uses the operations of
yanking and putting. Yanking consists of copying part of a
file into a special buffer; putting copies that buffer into
another part of the file.
To yank text, use the "y" operator (y<motion>, yy, or
Y) in the same manner as the delete or change operators.
Then move the cursor and use the put command (p) or put-
before command (P) to put the text elsewhere. For example,
5G yy 9G p
places another copy of the fifth line of the file after the
ninth line.
The delete and change operators also save the deleted
text in a yank buffer. Thus the command "xp" (actually two
commands) exchanges two characters by deleting the first and
reinserting it after the second.
In addition to the default yank buffer, VI has 26 other
yank buffers, tagged by (lower-case) letters of the alpha-
bet. To let a yank, put, delete, or change command command
refer to one of these buffers, precede the command with the
quote character and the letter of the buffer.
Transferring text between files can be done in one of
several ways. First, the command
:r name
reads the named file into the current file, following the
current line.
The reverse of this operation is the command,
:p name
which puts the buffer into a file of the given name, de-
stroying the file's previous contents, if any. "x:p and
:"xp are also valid; both do the same as :p with buffer x.
The last wat of transferring text between files is to
yank one or more pieces of text, switch the main file via
:e name
or :e! name
and then put the text into the new main file.
Helpful Hints
------- -----
In addition to deleting the current line in insert and
last line modes, the Escape key can be used to delete a
partially complete command. It also momentarily enlarges
the cursor. This makes it easier to see--it is easy to lose
the cursor after a locate operation.
To insert an escape code into the file, use control-[
or Alt-27.
One feature that VI currently lacks is the ability to
change all occurrences of a given string to another string.
This can be done with alternate uses of the "n" and "."
commands (and a little patience).
------------------------------------------------------------
The above is a tutorial introduction to some of the
most common VI commands. A list of all VI commands appears
in the command summary, below.
Command Summary
------- -------
Colon commands:
:w [name] write to file
:q quit
:q! abort
:wq [name] write and quit
:e name edit new file
:e! name discard corrections and edit new file
:f or ^G print file name, status, and length
:v print VI version
:r name read file into current file
:["x]p name put to file
Character motions:
h or Backspace back one character
Space or Rightarrow forward one character
^N or Downarrow next line, same column
^P or Uparrow previous line, same column
$ end of line
0 beginning of line
_ first non-white in line
w next word
b back one word
e end of word
W, B, E same as w, b, e, with blank-delimited words
% match (), [], or {}.
/string search
?string backwards search
/<cr> or ?<cr> forward or backwards search, same pattern
n repeat last search
N repeat last search, opposite direction
fx find next occurrence of x
Fx find previous x
tx move up to x
Tx up to x, backwards
; repeat last f, F, t, or T
, reverse of ,
Line motions:
+ or <cr> next line (first nonwhite)
- previous line
H or Home top of screen
M middle of screen
L or End last line of screen
nG go to nth line (end default)
Operators:
d<motion>, dd, D delete
c<motion>, cc, C change
y<motion>, yy, Y yank
Insert Mode:
i or Insert insert before current character
a insert after current character
I insert before first nonblank character in line
A append to end of line
o open after current line
O open before current line
Other modification commands:
x or Delete delete character
X delete previous character
s delete character and enter insert mode
r replace character
J join two lines
p put yanked text
P put yanked text before current line or character
u undo previous command
. repeat previous command
Screen commands:
^L redraw screen
^F or PgDn forward one screen
^B or PgUp back one screen
^U, ^D up (or down) 1/2 screen
z<cr> or zh redraw with current line on top
z<cr> or zm redraw with current line in middle
z<cr> or zl redraw with current line at bottom